package com.testmanager.testmananger.practiseDemo.testNGPrictise;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.apache.bcel.classfile.Code;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 用于测试testng使用
 * 此接口收到数据 ，交数据加上时间戳后 再返回，时间戳加在header中 和  timestamp中
 * 另根据json中的code来决定返回的响应码
 */

@Slf4j
@RestController
@RequestMapping("/testng")
public class Mock1 {

    @PostMapping("/samerep")
    public ResponseEntity<JSONObject> returnSameBody(@RequestBody JSONObject json){
        int code = 0;
        if (json.containsKey("code")){
            code = Integer.valueOf((Integer) json.get("code"));
        }else {
            code = 200;
        }


        json.put("timestamp", LocalDateTime.now());


        return  ResponseEntity.status(code).body(json);
    }



    @PostMapping("/samerepstring")
    public ResponseEntity returnSameRepString(@RequestBody String str){
        JSONArray var1 = new JSONArray();
        var1.add("123456");

        return ResponseEntity.ok(str+var1);
    }


}
